package com.smart.five.ioc.java.configuration.spring;

import com.smart.five.ioc.java.configuration.LoginService;
import com.smart.five.ioc.java.configuration.bean.Appconf;
import com.smart.five.ioc.java.configuration.bean.ServiceConfig;
import com.smart.five.ioc.java.configuration.bean.ServiceConfig2;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class MoreJavaConfigSpring {
    public static void main(String[] args) {
        //使用@Configuration类提供的bean定义信息启动容器
        AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext();
        //注册多个@Configuration配置类
        ac.register(Appconf.class);
        ac.register(ServiceConfig.class);

        //刷新容器以应用这些注册的配置类
        ac.refresh();

        LoginService loginService = (LoginService) ac.getBean("loginService");
        System.out.println(loginService);

        //可以通过Import将多个配置类组装在一个配置类中
        AnnotationConfigApplicationContext ac1 = new AnnotationConfigApplicationContext(ServiceConfig2.class);
        LoginService loginService2 = (LoginService) ac.getBean("loginService");
        System.out.println(loginService2);
    }
}
